# -*- coding:utf-8 -*-

import sys,os,time
import ConfigParser
from app.common.Singleton import Singleton

class Config():
    __metaclass__ = Singleton
    def __init__(self, path):
        self.path = path
        self.cf = ConfigParser.ConfigParser()
        self.cf.read(path)

    def get(self, field, key):
        try:
            return self.cf.get(field, key)
        except:
            print ('get ', field, key, ' from ', self.path, 'failed')
            return ''

    def set(self, field, key, value):
        try:
            self.cf.set(field, key, value)
            self.cf.write(open(self.path, 'w'))
        except:
            print ('write file ', self.path, field, key, value, ' failed')

